#-*- coding = utf-8 -*-
#@Time : 2021/1/24 22:16
#@Author : yzh
#@File : __init__.py.py
#@Software : PyCharm
import os
from api.queryGrade import querygrade
from resources.NP import username

# 定义存储位置
global save_path
save_path = 'F:\querygrade'


# 创建文件夹
def createFile(file_path):
    if os.path.exists(file_path) is False:
        os.makedirs(file_path)
    # 切换路径至上面创建的文件夹
    os.chdir(file_path)

def main():
    body = querygrade()
    createFile(save_path)
    file_name = str(username) + "-Grade.html"
    f = open(file_name, "w", encoding="utf-8")
    f.write("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<title>查询成绩</title>\n</head>")
    f.write(body)
    f.write("</html>")
    print(file_name, '成绩保存成功！')
    f.close()

if __name__ == '__main__':
    main()